package br.pucrio.inf.aaaong.models.domain.database.dao.basic;

import java.sql.SQLException;

import br.pucrio.inf.aaaong.models.database.exceptions.PostgreSQLConstraintException;
import br.pucrio.inf.aaaong.models.database.update.UpdateQueryExecutor;
import br.pucrio.inf.aaaong.models.database.update.UpdateQueryParamsPreparer;
import br.pucrio.inf.aaaong.models.database.update.UpdateQueryParamsSetter;
import br.pucrio.inf.aaaong.models.domain.database.dao.basic.beans.PreInscritoBean;

public class PreInscritoDAO {
	private static final String QUERY_INSERT = "insert into PreInscrito(id_adolescente,"
			+ "indicacao,data_inscricao,cpf_assistente_pre_inscreveu)"
			+ "values(?,?,?,?)";
	
	private UpdateQueryExecutor queryExecutor;

	public PreInscritoDAO(UpdateQueryExecutor queryExecutor) {
		this.queryExecutor = queryExecutor;
	}

	public void insert(final PreInscritoBean preInscrito) throws PostgreSQLConstraintException {
		queryExecutor.execute(QUERY_INSERT, new UpdateQueryParamsPreparer() {
			
			@Override
			public void prepareParameters(UpdateQueryParamsSetter params) throws SQLException {
				params.setInt(preInscrito.getId());
				params.setString(preInscrito.getIndicacao());
				params.setCalendar(preInscrito.getDataInscricao());
				params.setString(preInscrito.getCpfAssistentePreInscreveu());
			}
		});
	}

}
